﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="RoleAssign.ascx.cs" Inherits="Admin_MemberAdmin_Controls_RoleAssign" %>
<style type="text/css">
    .rolemiddle
    {
        height: 200px;
        position: relative;
        width:50px;
    }
    .rolemiddle div
    {
        position: absolute;
        top: 50%;
        left: 0;
    }
    .rolemiddle div div
    {
        position: relative;
        top: -50%;
        left: 0;
    }
</style>

<script type="text/javascript" language="javascript">
    $(document).ready(function() {
        roleAssignReset(null, null);
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(roleAssignReset);

    });

    function roleAssignReset(sender, args) {
        $("#<%=lbNoAssignRole.ClientID%>").dblclick(function() {

            assignRole();
        });

        $("#<%=lbAssignRole.ClientID %>").dblclick(function() {
            noAssignRole();
        });

        $("#assignButton").click(function() {

            assignRole();

        });
        $("#noAssignButton").click(function() {
            noAssignRole();
        });
    }

    function noAssignRole() {
        var noAssign = $("#<%=lbNoAssignRole.ClientID%>");
        var assign = $("#<%=lbAssignRole.ClientID %>");
        assignRoleFrom(assign, noAssign);
    }
    function assignRole() {
        var noAssign = $("#<%=lbNoAssignRole.ClientID%>");
        var assign = $("#<%=lbAssignRole.ClientID %>");
        assignRoleFrom(noAssign, assign);
    }


    function assignRoleFrom(from, to) {
        from.children().each(function(i) {

            if (this.selected) {
                var assignValue = $(this).val();
                var assignText = $(this).text();
                from.children("option[value='" + assignValue + "']").remove();
                to.append("<option value='" + assignValue + "'>" + assignText + "</option>");
                var roleSubmitField = $("#<%=HiddenBoxAssignRoleId.ClientID %>");
                if (to.attr("id") == "<%=lbAssignRole.ClientID %>") {
                    roleSubmitField.val(roleSubmitField.val() + "," + assignValue);
                }
                else {
                    var newValue = roleSubmitField.val().replace("," + assignValue, "");
                    roleSubmitField.val(newValue);
                }
            }
        });
    }    
</script>

<input type="hidden" id="HiddenBoxAssignRoleId" runat="server" />
<div style="float: left;">
    <asp:Label ID="label1" Text="未分配角色:" runat="server" AssociatedControlID="lbNoAssignRole"></asp:Label>
    <select id="lbNoAssignRole" runat="server" datatextfield="Name" datavaluefield="Name"
        multiple="true" name="lbNoAssignRole" size="10" style="width: 150px; height: 200px">
    </select>
</div>
<div class="rolemiddle" style="float: left;">
    <div>
        <div>
            <p>
                <input type="button" id="assignButton" style="clear: both" class="ui-state-default ui-corner-all"
                    value=">>" />
            </p>         
            <p>
                <input type="button" id="noAssignButton" style="clear: both" class="ui-state-default ui-corner-all"
                    value="<<" /></p>
        </div>
    </div>
</div>
<div style="float: left;">
    <asp:Label ID="label2" Text="已分配角色:" runat="server" AssociatedControlID="lbAssignRole"></asp:Label>
    <select id="lbAssignRole" runat="server" datatextfield="Name" datavaluefield="Name"
        multiple="true" name="lbAssignRole" style="width: 150px; height: 200px" size="10">
    </select>
</div>
